package cn.edu.gzhu.workOrderManagement.enumeration;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;


import java.util.Objects;

@Getter
@Slf4j
public enum WorkOrderProcessingStatusEnum {
    COMMON_HEAD_BUS_PENDING("普通工单待总部商务分配",100),
    COMMON_BRANCH_BUS_PENDING("普通工单待分公司商务处理",101),
    COMMON_BRANCH_SUP_PENDING("普通工单待分公司主管处理",102),
    //COMMON_AGENT_PROCESSING("普通工单分支机构工单处理员处理中",103),
    COMMON_BRANCH_BUS_AUDITING("普通工单待分公司商务审核",103),
    COMMON_HQ_BUS_AUDITING("普通工单总待部商务审核",104),
    COMMON_END("普通工单完结",105),

    REPEAT_HEAD_BUS_PENDING("重诉工单待总部商务分配",200),
    REPEAT_BRANCH_BUS_PENDING("重诉工单待分公司商务处理",201),
    REPEAT_BRANCH_SUP_PENDING("重诉工单待分公司主管处理",202),
    //REPEAT_AGENT_PROCESSING("重诉工单分支机构工单处理员处理中",203),
    REPEAT_BRANCH_BUS_AUDITING("重诉工单待分公司商务审核",203),
    REPEAT_HQ_BUS_AUDITING("重诉工单待总公司商务审核",204),
    REPEAT_BRANCH_MANAGER_AUDITING("重诉工单待分公司负责人审核",205),
    REPEAT_HQ_MANAGER_AUDITING("重诉工单待总公司负责人审核",206),
    REPEAT_HQ_BUS_FINALLY_AUDITING("重诉工单待总部商务最终审核",207),
    REPEAT_END("重诉工单完结",208),

    MATERIAL_HEAD_BUS_PENDING("材料调取待总部商务分配",300),
    MATERIAL_BRANCH_BUS_PENDING("材料调取工单待分公司商务处理",301),
    MATERIAL_BRANCH_SUP_PENDING("材料调取工单待分公司主管处理",302),
    //MATERIAL_AGENT_PROCESSING("材料调取工单分支机构材料处理员处理中",303),
    MATERIAL_BRANCH_BUS_AUDITING("材料调取工单待分公司商务审核",303),
    MATERIAL_HQ_BUS_AUDITING("材料调取工单待总公司商务审核",304),
    MATERIAL_HQ_AUDITOR_AUDITING("材料调取工单待总公司稽查审核",305),
    MATERIAL_HQ_BUS_SECOND_AUDITING("材料调取工单待总公司商务二次审核",306),
    MATERIAL_BRANCH_MANAGER_AUDITING("材料调取工单待分公司负责人审核",307),
    MATERIAL_HQ_MANAGER_AUDITING("材料调取工单待总公司负责人审核",308),
    MATERIAL_HQ_BUS_FINALLY_AUDITING("材料调取工单待总公司商务最终审核",309),
    MATERIAL_END("材料处理工单完结",310);

    private final String description;

    private final Integer status;


    WorkOrderProcessingStatusEnum(String description, Integer status){
        this.description = description;
        this.status = status;
    }
    public static WorkOrderProcessingStatusEnum value2Object(Integer status){

        for (WorkOrderProcessingStatusEnum workOrderProcessingStatusEnum : WorkOrderProcessingStatusEnum.values()) {
            if (Objects.equals(workOrderProcessingStatusEnum.getStatus(), status)) {
                return workOrderProcessingStatusEnum;
            }
        }
        log.error("不合法的工单状态: " + status + "。");
        return null;
    }
    public static WorkOrderProcessingStatusEnum value2Object(String description){
        for (WorkOrderProcessingStatusEnum workOrderProcessingStatusEnum : WorkOrderProcessingStatusEnum.values()) {
            if (Objects.equals(workOrderProcessingStatusEnum.getDescription(), description)) {
                return workOrderProcessingStatusEnum;
            }
        }
        log.error("不合法的工单状态: " + description + "。");
        return null;
    }

    public WorkOrderProcessingStatusEnum toNextStatus(){
        if (this.equals(COMMON_END)||this.equals(REPEAT_END)||this.equals(MATERIAL_END)){
            return null;
        }
        Integer nextStatus = this.status+1;
        return value2Object(nextStatus);
    }
    public WorkOrderProcessingStatusEnum toPreviousStatus(){
        Integer previous = this.status-1;
        return value2Object(previous);
    }


    public static WorkOrderProcessingStatusEnum getCommonStartStatus(){
        return COMMON_BRANCH_BUS_PENDING;
    }
    public static WorkOrderProcessingStatusEnum getRepeatStartStatus(){
        return REPEAT_BRANCH_BUS_PENDING;
    }
    public static WorkOrderProcessingStatusEnum getMaterialStartStatus(){
        return MATERIAL_BRANCH_BUS_PENDING;
    }

    public static WorkOrderProcessingStatusEnum getMaterialEndStatus(){
        return MATERIAL_END;
    }
    public static WorkOrderProcessingStatusEnum getRepeatEndStatus(){
        return REPEAT_END;
    }
    public static WorkOrderProcessingStatusEnum getCommonEndStatus(){
        return COMMON_END;
    }
}
